<?php
class messageModel extends appModel{
    
    public function isApply($wxid)
    {
        $sql = "SELECT id FROM ".$this->table("group_info")." WHERE wxid = $wxid LIMIT 1 ";
        $id = $this->getOne($sql);
        if($id)
        {
            return false;
        }else
        {
            return true;
        }
    }
    public function isApplyParlour($wxid)
    {
        $sql = "SELECT id FROM ".$this->table("parlour")." WHERE wxid = $wxid LIMIT 1 ";
        $id = $this->getOne($sql);
        if($id)
        {
            return false;
        }else
        {
            return true;
        }
    }
    public function isApplyChild($wxid)
    {
        $sql = "SELECT id FROM ".$this->table("parlour2")." WHERE wxid = $wxid LIMIT 1 ";
        $id = $this->getOne($sql);
        if($id)
        {
            return false;
        }else
        {
            return true;
        }
    }
    
    public function getCommentParlour()
    {
        $sql = "SELECT  p1.comment,p2.nickname,p2.headimgurl,p1.wxid FROM ".$this->table("parlour_comment")." p1 ".
                " LEFT JOIN ".$this->table("wxusers")." p2 ON p1.wxid = p2.wxid ".
                " WHERE p1.status = 1 ORDER BY p1.create_time desc ";
        $res = $this->getAll($sql);
        foreach ($res as $k=>$v)
        {
            if($v['wxid'] == -1){
                $res[$k]['status'] = "immediately";
            }
        }
        return $res;
    }
    
    public function getCommentMobile()
    {
        $sql = "SELECT  p1.comment,p2.nickname,p2.headimgurl,p1.wxid FROM ".$this->table("parlour_comment")." p1 ".
            " LEFT JOIN ".$this->table("wxusers")." p2 ON p1.wxid = p2.wxid ".
            " WHERE p1.status = 1 ORDER BY p1.create_time desc ";
        $res = $this->getAll($sql);
        foreach ($res as $k=>$v)
        {
            if($v['wxid'] == -1){
                $res[$k]['status'] = "immediately";
            }
        }
        $sql = "SELECT count(*) FROM ".$this->table("parlour_comment")." ";
        $result['count'] = $this->getOne($sql);
        $result['comment'] = $res;
        return $result;
    }
    
    public function getCount()
    {
        $sql = "SELECT count(*) FROM ".$this->table("parlour_comment")." ";
        return $this->getOne($sql);
    }
    
    public function getRecord($wxid)
    {
        $sql = "SELECT wxid,nickname,headimgurl FROM ".$this->table("wxusers")." WHERE wxid = $wxid LIMIT 1  ";
        $record = $this->getRow($sql);
        if($record){
            return $record;
        }
        return false;
    }
    
    public function isApplyGuangfu($wxid)
    {
        $sql = "SELECT id FROM ".$this->table("guangfu")." WHERE wxid = $wxid LIMIT 1 ";
        $id = $this->getOne($sql);
        if($id)
        {
            return false;
        }else
        {
            return true;
        }
    }
}